package com.lenovo.smarttraffic.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lenovo.smarttraffic.R;
import com.lenovo.smarttraffic.bean.CarInfo;
import com.lenovo.smarttraffic.bean.UserBean;
import com.lenovo.smarttraffic.util.Utils;

public class ETCMoneyAdapter extends BaseAdapter {

    private CarInfo account;
    private UserBean user;

    private Context context;

    public ETCMoneyAdapter(Context context, CarInfo account, UserBean user) {
        this.context = context;
        this.account = account;
        this.user = user;
    }

    @Override
    public int getCount() {
        return Math.min(account.getROWS_DETAIL().size(), user.getROWS_DETAIL().size());
    }

    @Override
    public Object getItem(int position) {
        return account.getROWS_DETAIL().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item_etc_money, parent, false);
            holder = new ViewHolder();
            holder.carId = convertView.findViewById(R.id.car_id);
            holder.car_img = convertView.findViewById(R.id.car_img);
            holder.title = convertView.findViewById(R.id.title);
            holder.value = convertView.findViewById(R.id.value);
            holder.money = convertView.findViewById(R.id.money);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (account.getROWS_DETAIL() != null && account.getROWS_DETAIL().size() > 0
                && user.getROWS_DETAIL() != null && user.getROWS_DETAIL().size() > 0) {

            CarInfo.ROWSDETAILBean rowsdetailBean = account.getROWS_DETAIL().get(position);
            UserBean.ROWS_DETAIL rowsdetailBean2 = user.getROWS_DETAIL().get(position);

            holder.carId.setText(String.valueOf(rowsdetailBean.getNumber()));

            holder.car_img.setBackgroundResource(Utils.getCarBandRes(rowsdetailBean.getCarbrand()));

            holder.title.setText(rowsdetailBean.getCarnumber());

            holder.value.setText(String.format("车主：%s", rowsdetailBean2.getPname()));

            holder.money.setText("余额：0元");

        }


        return convertView;
    }

    static class ViewHolder {
        TextView carId, title, value, money;
        View car_img;
    }
}
